<template>
  <BasicModal
    @register="register"
    title="请给出自评评分和完成情况"
    :okButtonProps="{ disabled: false }"
    @ok="upTimeLast"
  >
    <div style="margin-bottom: 25px; margin-left: 30px">
      评分状态
      <RadioGroup v-model:value="value1" style="margin-left: 10px" button-style="solid">
        <RadioButton value="10">未完成</RadioButton>
        <RadioButton value="20">进行中</RadioButton>
        <RadioButton value="30">已完成</RadioButton>
      </RadioGroup>
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px; margin-top: 10px">
      自我评分
      <!-- -{{ showTrue }}--{{ upLoadShow }} -->
      <a-input v-model:value="zipingfenshu" style="width: 200px; margin-left: 5px" />
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px">
      完成情况
      <!-- v-show="markResultVOList.length !== 0" -->
      <a-textarea
        v-model:value="zipingfenshuneirong"
        style="width: 380px; margin-left: 5px"
        :auto-size="{ minRows: 2, maxRows: 6 }"
      />
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { Radio } from 'ant-design-vue';
  import { taskInterimMark, taskInterimMarkPUT } from '/@/api/basic/import/index';
  import { useMessage } from '/@/hooks/web/useMessage';
  const emit = defineEmits(['success', 'register']);
  const RadioGroup = Radio.Group;
  const RadioButton = Radio.Button;
  const { createMessage } = useMessage();
  let zipingfenshuneirong: any = ref();
  let zipingfenshu: any = ref();
  let record: any = ref();
  const value1 = ref<string>('10');

  const [register, { closeModal }] = useModalInner((data) => {
    // 赋值
    record.value = { ...data?.detailResule };
    if (record.value.markResultVOList) {
      for (var i = 0; i < record.value.markResultVOList.length; i++) {
        if (record.value.markResultVOList[i].isDefault) {
          if (record.value.markResultVOList[i].score !== undefined) {
            zipingfenshu.value = record.value.markResultVOList[i].score;
            zipingfenshuneirong.value = record.value.markResultVOList[i].remarks;
            value1.value = record.value.markResultVOList[i].targetState;
          }
        }
      }
    }
  });
  async function upTimeLast() {
    if (zipingfenshu.value !== undefined && zipingfenshuneirong.value !== undefined) {
      if (zipingfenshu.value > record.value.targetScore) {
        createMessage.error(`自评分数不能大于项目分值，请重新填写`);
      } else {
        if (record.value.markResultVOList.length !== 0) {
          for (var i = 0; i < record.value.markResultVOList.length; i++) {
            if (record.value.markResultVOList[i].isDefault) {
              if (record.value.markResultVOList[i].score !== undefined) {
                const arrchage = {
                  targetId: record.value.id,
                  score: zipingfenshu.value,
                  remarks: zipingfenshuneirong.value,
                  targetState: value1.value,
                  id: record.value.markResultVOList[i].id,
                };
                await taskInterimMarkPUT(arrchage);
                emit('success');
              }
            } else {
              const arr = {
                targetId: record.value.id,
                score: zipingfenshu.value,
                remarks: zipingfenshuneirong.value,
                targetState: value1.value,
              };
              await taskInterimMark(arr);
              zipingfenshuneirong.value = '';
              zipingfenshu.value = '';
              value1.value = '10';
              emit('success');
            }
          }
        } else {
          const arr = {
            targetId: record.value.id,
            score: zipingfenshu.value,
            remarks: zipingfenshuneirong.value,
            targetState: value1.value,
          };
          await taskInterimMark(arr);
          zipingfenshuneirong.value = '';
          zipingfenshu.value = '';
          value1.value = '10';
          emit('success');
        }
        closeModal();
      }
    } else {
      createMessage.error(`评分或评分依据不能为空`);
    }
  }
</script>
